package com.xnx3.banmahuishou.wangge.controller;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Resource;
import com.xnx3.j2ee.entity.User;
import com.xnx3.j2ee.pluginManage.controller.BasePluginController;
import com.xnx3.j2ee.service.SqlService;

/**
 * 这个包下所有Controller父类
 * @author 王晓龙
 */
public class BaseController extends BasePluginController{
	@Resource
	private SqlService sqlService;
	
	/**
	 * 根据手机号查询除了这个用户其他用户有没有同样的手机号。若手机号不存在，返回null
	 * @param phone 手机号
	 * @param id id 用户id
	 * @author 王晓龙
	 */
	public User findByPhone(Object phone,int id){
		String string = "SELECT * FROM user WHERE phone = " + phone + " AND id != " + id + " AND authority = 10 AND isfreeze = 0 ";
		List<User> list = sqlService.findBySqlQuery(string, User.class);
		if(list.size() > 0){
			return list.get(0);
		}else{
			return null;
		}
	}
	
	/**
	 * 判断手机号是否合法
	 * @param telNum 手机号
	 * @author 王晓龙
	 */
	public static boolean isMobiPhoneNum(String telNum){
		String regex = "1\\d{10}";
        Pattern p = Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(telNum);
        return m.matches();
	}
}
